from rest_framework import serializers

from six_it.models import Enterprise, Recruit


class FourthRecruitsSerializer(serializers.ModelSerializer):
    '''4.职位详情'''

    class Meta:
        model = Recruit
        fields = ["id"]


class ThirdEnterpriseSerializer(serializers.ModelSerializer):
    '''3.企业详情'''
    recruits = FourthRecruitsSerializer(many=True)

    class Meta:
        model = Enterprise
        fields = ["id", "name", "labels", "logo", "summary", "recruits"]


class SecondRecruitsSerializer(serializers.ModelSerializer):
    '''2.职位详情序列化器类'''

    enterprise = ThirdEnterpriseSerializer(read_only=True)

    class Meta:
        model = Recruit
        fields = ["id", "jobname", "salary", "condition", "education", "type", "city", "createtime", "labels",
                  'enterprise']


class FirstEnterpriseSerializer(serializers.ModelSerializer):
    '''1.企业详情序列化器类'''

    recruits = SecondRecruitsSerializer(many=True)

    class Meta:
        model = Enterprise
        fields = ["id", "name", "summary", "content", "city", "address", "labels", "coordinate", "logo", "url",
                  "visits", "recruits", "users"]
